Programming languages often use pointers, which are portions of memory that point to a memory address or block of memory. Memory is managed using commonly known management techniques. These techniques attempt to control the allocation of memory and to ensure that the main memory is shared fairly.
A typical system will provide a Memory Management Unit (MMU) that will manage the virtual memory space of the system. The MMU may be located on the central processing unit (CPU). In another embodiment, the MMU may be located on a separate chip. The MMU typically includes a table that maps virtual addresses to physical addresses. Further, the MMU may throw a trap if an attempt is made to access a virtual memory address that is not associated to a physical memory address. A process in memory may specify certain portions of memory to be used by the process. For example, instructions for the process may be located in one portion of memory and the data associated with or used by the process may be located in another portion of the memory (e.g., memory range). Ranges of memory used to store instructions or data may be write-protected, not allowing any new data to overwrite the existing memory content. The MMU may detect when a process attempts to write data to a protected memory region and throw a trap.
A commonly known memory management technique is garbage collection. Garbage collection may help optimize the use of the available memory by automatically freeing unused objects in a running program, and by avoiding common types of memory mismanagement. Garbage collection ensures that unused memory will be cleaned up and made available for other objects to use. A generational garbage collector may provide a grouping of objects based on age. An object that has been in use for certain period of time may be promoted to an older generation. The older generation objects are destroyed less frequently, therefore saving processing time during garbage collection.
Many applications (e.g., including garbage collectors) make use of pointers to link sets of elements (or objects) together (e.g., linked lists, trees, etc.). Occasionally, an application may restrict a pointer associated with one set of elements (e.g., Sx) from pointing to another set of elements (e.g., Sy). Restricting pointers in this manner allows the application to remain stable, avoid unpredictable results, protect the security of the information, and/or improve the performance of the computer system.
Currently, a few methods are available to determine whether a pointer associated with an element from Sx is illegally attempting to point to an element from Sy. One example is used in a generational garbage collector. Specifically, if a pointer is created, pointing from an object in the old generation to an object in the new generation, the event should be detected and treated specially. To detect the creation of such a pointer, the garbage collector is initially configured to allow an old generation object to be placed at a virtual address with a “small” high-byte value (e.g., 0, 1, etc.), whereas the new generation object may be placed at a virtual address with a “large” high-byte value (e.g., hexadecimal value E, hexadecimal value F, etc.). Next, a determination is made whether an old generation object is attempting to point to a new generation object, by masking off the high-byte value of the destination and comparing the high-byte value from the source to the destination. If the high-byte value from the source is less than the destination, then the special condition is detected and dealt with appropriately. Thus, by performing numerous comparisons to detect the creation of such special pointers, the integrity of the memory managed by the garbage collector is maintained.